﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System.Diagnostics;
using System.Windows.Documents;
using System.Windows.Markup;
using System.IO;
using System.Xml;



namespace MoreEPG.ViewModel
{
    
    public class AboutViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the AboutViewModel class.
        /// </summary>
        public AboutViewModel()
        {
            InitCommands();
            this.Version = "Version : " + v.ToString();

            string rawXamlText = "";
            
            
            StreamReader streamReader = File.OpenText("View/AboutDocument.de.xaml");
            rawXamlText = streamReader.ReadToEnd();

            this.Document = XamlReader.Load(new XmlTextReader(new StringReader(rawXamlText))) as FlowDocument;
        }

        


        private void InitCommands()
        {
            this.CFClick = new RelayCommand(
                () => OnClick());
        }

        private void OnClick()
        {
            Process.Start("http://www.tvmovie.de/ClickFinder.57.0.html");
        }

        public RelayCommand CFClick
        {
            get;
            private set;
        }

        /// <summary>
        /// The <see cref="Version" /> property's name.
        /// </summary>
        public const string VersionPropertyName = "Version";

        System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

        private string _version = "";

        /// <summary>
        /// Gets the Version property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public string Version
        {
            get
            {
                return _version;
            }

            set
            {
                if (_version == value)
                {
                    return;
                }

                
                _version = value;

              

                // Update bindings, no broadcast
                RaisePropertyChanged(VersionPropertyName);

               
            }
        }

        
        /// <summary>
        /// The <see cref="Document" /> property's name.
        /// </summary>
        public const string DocumentPropertyName = "Document";
        
        private FlowDocument _document;

        /// <summary>
        /// Gets the Document property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public FlowDocument Document
        {
            get
            {
                return _document;
            }

            set
            {
                if (_document == value)
                {
                    return;
                }

                
                _document = value;

               

                // Update bindings, no broadcast
                RaisePropertyChanged(DocumentPropertyName);

            }
        }
       
    }
}